<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>药品信息添加</title>

<%@ include file="/WEB-INF/component/commonCSS.jsp" %> 
<style type="text/css">
    	div.box-body {
    		margin-top:7px;
    	}
    </style>

</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>药品信息新增</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="compList.jsp">药品库管理</a></li>
            <li class="active"><a href="compEdit.jsp">药品信息新增</a></li>
        </ol>
    </section>
    <section class="content">
      <form role="form" id="form1" class="form-horizontal" action="${ctx }/stdDrug/addInfo.html" method="post">
        <div class=" box box-success">
            <!-- form start -->
                <div class="box-body">                               
                <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">药品编码：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="drugCode" name="drugCode" placeholder="药品编码" type="text">
                        </div>
                        <label class="col-sm-2 text-right">通用名：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="drugName" name="drugName" placeholder="通用名" type="text">
                        </div>
                   </div>
                <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">通用名英文：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="drugNameEng" name="drugNameEng" placeholder="通用名英文" type="text">
                            </select>
                        </div>
                        <label class="col-sm-2 text-right">商品名：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="busName" name="busName" placeholder="商品名" type="text">
                        </div>
                   </div>
                
                <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">剂型：</label>
                        <div class="col-sm-4 text-left">
                        <div class="col-sm-6 text-left">
                        <input type="hidden" id="formId" name="formId" value=""/>
                            <select class="form-control" name="drugform1" id="drugform1">
                            </select>
                            </div>
                            <div class="col-sm-6 text-left">
                            <select class="form-control" name="drugform2" id="drugform2">
                            </select>
                            </div>
                        </div>
                        <label class="col-sm-2 text-right">规格：</label>
                        <div class="col-sm-3 text-left">
                        <input type="hidden" id="specId" name="specId" value=""/>
                            <input class="form-control" readonly="readonly" id="txdrugspec" name="txdrugspec" placeholder="规格" type="text">
                        </div>
                        <div class="col-sm-1 text-left">
                        <a href="javascript:void(0)" onclick="selectSpec();" class="btn btn-default btn-sm" >选择</a>
                        </div>
                   </div>
                <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">转换系数：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="factor" name="factor" placeholder="转换系数" type="text">
                        </div>
                        <label class="col-sm-2 text-right">单位：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="unit" name="unit" placeholder="单位" type="text">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                    
                    <label class="col-sm-2 text-right">材质：</label>
                        <div class="col-sm-4 text-left">
                            <select class="form-control" name="materialId" id="materialId">
                            </select>
                        </div>
                        <label class="col-sm-2 text-right">生产企业：</label>
                        <div class="col-sm-3 text-left">
                            <input class="form-control" readonly="readonly" id="comp" name="comp" placeholder="生产企业" type="text">
                            <input type="hidden" value="" name="prodPompId" id="prodPompId"/>
                            
                        </div>
                        <div class="col-sm-1 text-left">
                        <a href="javascript:void(0)" onclick="selectComp();" class="btn btn-default btn-sm" >选择</a>
                        </div>
                        
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">批准文号：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="approvalCode" name="approvalCode" placeholder="批准文号" type="text">
                        </div>
                        <label class="col-sm-2 text-right">批准日期：</label>
                        <div class="col-sm-4 text-left">
                         <input class="form-control" type="text" id="approvalDate" name="approvalDate" placeholder="yyyy-MM-dd" data-provide="datepicker" data-date-fmt="yyyy-MM-dd" />
                        </div>
                   </div>
                   
                   
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">基本药物属性：</label>
                        <div class="col-sm-4 text-left">
                            <select class="form-control" id="drugAttr" name="drugAttr">
                            	<!-- <option value="">请选择</option>
                            	<option value="1">国家基本药物（2012版）</option>
                            	<option value="2">省增补基本药物</option>
                            	<option value="3">其他</option> -->
                            </select>
                        </div>
                        <label class="col-sm-2 text-right">基药序号：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="drugIndex" name="drugIndex" placeholder="基药序号" type="text">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">药理分类：</label>
                        <div class="col-sm-4 text-left">
                        <input type="hidden" name="pharId" id="pharId" value=""/>
                        <div class="col-sm-3 text-left">
                        <select class="form-control" id="pharbig">
                            </select>
                            </div>
                            <div class="col-sm-3 text-left">
                            <select class="form-control" id="phar1">
                            </select>
                            </div>
                            <div class="col-sm-3 text-left">
                            <select class="form-control" id="phar2">
                            </select>
                            </div>
                            <div class="col-sm-3 text-left">
                            <select class="form-control" id="phar3">
                            </select>
                            </div>
                        </div>
                         <label class="col-sm-2 text-right">专利类型：</label>
                        <div class="col-sm-4 text-left">
                            <select class="form-control" id="patternType" name="patternType">
                            
                            </select>
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        
                        <label class="col-sm-2 text-right">药品来源：</label>
                        <div class="col-sm-4 text-left">
                            <select class="form-control" id="drugSource" name="drugSource">
                            <option value="">请选择</option>
                            <option value="1">国产</option>
                            <option value="2">进口</option>
                            <option value="9">不详</option>
                            </select>
                        </div>
                        
                        <label class="col-sm-2 text-right">是否低价药：</label>
                        <div class="col-sm-4 text-left">
                            <select class="form-control" id="isLowprice" name="isLowprice">
                            <option value="">请选择</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                            <option value="9">未知</option>
                            </select>
                        </div>
                    </div>
                      <div class="form-group  form-group-xs">
                      <label class="col-sm-2 text-right">是否农合：</label>
                        <div class="col-sm-4 text-left">
                            <select class="form-control" id="isAgriculture" name="isAgriculture">
                            <option value="">请选择</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                            <option value="9">未知</option>
                            </select>
                        </div>
                        <label class="col-sm-2 text-right">是否医保：</label>
                        <div class="col-sm-4 text-left">
                            <select class="form-control" id="isHealthcare" name="isHealthcare">
                            <option value="">请选择</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                            <option value="9">未知</option>
                            </select>
                        </div>
                    </div>
                    
                    
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">药品本位码：</label>
                        <div class="col-sm-10 text-left">
                            <input class="form-control" id="drugStdCode" name="drugStdCode" placeholder="药品本位码" type="text">
                        </div>

                   </div>
                   
                   <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">药品本位码备注：</label>
                        <div class="col-sm-10 text-left">
                        <textarea class="form-control" id="drugStdcdRemark" name="drugStdcdRemark" rows="3" placeholder="药品本位码备注"></textarea>
                         <!-- <input class="form-control" id="drugstdcdremark" name="drugstdcdremark" placeholder="药品本位码备注" type="text"> -->
                        </div>
                        
                   </div>
                   
                   <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right">说明：</label>
                        <div class="col-sm-10 text-left">
                            <textarea class="form-control" id="remark" name="remark" rows="3" placeholder="说明 ..."></textarea>
                        </div>
                        
                   </div>
                    
                    
                    
                    
                    
                 <div class="box-footer text-center">
                    <button type="button" onclick="save();" class="btn btn-success btn-sm">保&nbsp;存</button>
                    <button type="button" onclick="back();" class="btn btn-danger btn-sm">返&nbsp;回</button>
                </div>
              </div>      
        </div>
       </form> 
        
        
        
        
        
         <div class="modal fade" id="selectComp" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel">选择生产企业</h5>
                    </div>
                    <div class="modal-body">
                        <form>
                        <div class=" box box-success">
            <div class="box-body">
            <div class="form-inline">
                    <div class="form-group form-group-xs">
                         企业编码： 
                        <input class="form-control" type="text" id="compCode" placeholder="企业编码" />
                    </div>
                    <div class="form-group form-group-xs">
                         企业名称： 
                        <input class="form-control" type="text" id="compName" placeholder="企业名称" />
                    </div>
                    
                    <button type="button" onclick="gridSerch()" class="btn btn-success btn-sm">查&nbsp;询</button>
                </div>
            </div>
        </div>
                        
                        <div class="form-group form-group-xs">
                                <table class="jqgrid col-sm-1" id="gridlist1"></table>
        <div id="gridpage1 col-sm-1"></div>
                            </div>
                        
                        
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" onclick="gridOk()" class="btn btn-primary btn-sm">选&nbsp;择</button>
                        <button type="button" class="btn btn-danger btn-sm" onclick="cleandata()">清&nbsp;空</button>
                    </div>
                </div>
            </div>
        </div>
        
        
        
       <!-- 选择规格 -->
        
        <div class="modal fade" id="selectSpec" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" >
            <div class="modal-dialog" >
                <div class="modal-content" style="background-color:#ecf0f5">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel">选择规格</h5>
                    </div>
                    <div class="modal-body">
                        <form>
                        <div class=" box box-success">
            <div class="box-body" >
            <div class="form-inline">
                    <div class="form-group form-group-xs">
                         规格名称： 
                        <input class="form-control" type="text" id="specName" placeholder="规格名称" />
                    </div>
                    
                    <button type="button" onclick="gridSpecSerch()" class="btn btn-success btn-sm">查&nbsp;询</button>
                </div>
            </div>
        </div>
                        
                        <div class="form-group form-group-xs">
                                <table class="jqgrid col-sm-1" id="gridlist2"></table>
        <div id="gridpage2 col-sm-1"></div>
                            </div>
                        
                        
                        </form>
                    </div>
                    <div class="modal-footer" style="background-color:#fff">
                        <button type="button" onclick="gridSpecOk()" class="btn btn-primary btn-sm">选&nbsp;择</button>
                        <button type="button" class="btn btn-danger btn-sm" onclick="cleanSpecdata()">清&nbsp;空</button>
                    </div>
                </div>
            </div>
        </div>
         <%@ include file="/WEB-INF/component/commonJS.jsp" %>  
    </section>
	<script type="text/javascript">
	$(document).ready(function (){
		$("#drugform1").HNSelect({
            url: "${pageContext.request.contextPath}/selectController/getForm.html", data: { ID: '0' },  defaultText: "<option value=''>请选择</option>",
            func: function () {
                $("#drugform2").HNSelect({
                    parent_selector: "#drugform1", url: "${pageContext.request.contextPath}/selectController/getForm.html", dataid: "ID",  defaultText: "<option value=''>请选择</option>",
                    
                });
            }
        });
		
		
		
		
		$("#pharbig").HNSelect({
            url: "${pageContext.request.contextPath}/selectController/getPhar.html", data: { ID: '0' },  defaultText: "<option value=''>请选择</option>",
            func: function () {
                $("#phar1").HNSelect({
                    parent_selector: "#pharbig", url: "${pageContext.request.contextPath}/selectController/getPhar.html", dataid: "ID",  defaultText: "<option value=''>请选择</option>",
                    func: function () {
                        $("#phar2").HNSelect({
                            parent_selector: "#phar1", url: "${pageContext.request.contextPath}/selectController/getPhar.html", dataid: "ID",  defaultText: "<option value=''>请选择</option>",
                            		func: function () {
                                        $("#phar3").HNSelect({
                                            parent_selector: "#phar2", url: "${pageContext.request.contextPath}/selectController/getPhar.html", dataid: "ID",  defaultText: "<option value=''>请选择</option>",
                        });
                    }
                });
                    }
                });
            }
        });
		
		$("#materialId").HNSelect({
            url: "${pageContext.request.contextPath}/selectController/getMaterial.html", data: { ID: '0' },  defaultText: "<option value=''>请选择</option>",
            
        });
		
		$("#drugAttr").HNSelect({
            url: "${pageContext.request.contextPath}/selectController/getDicSys.html", data: { ID: '110' },defaultselect:'${form.drugAttr}',  defaultText: "<option value=''>请选择</option>",
        });
		$("#patternType").HNSelect({
            url: "${pageContext.request.contextPath}/selectController/getDicSys.html", data: { ID: '111' },defaultselect:'${form.patternType}',  defaultText: "<option value=''>请选择</option>",
        });
	})
	 
	 function save(){
   	  $.HN.message.confirm('确定要保存吗？', '', '').on(function (e) {
             if (e) {
            	 
            	 if ($.trim($("#drugCode").val()).lenght<1){
            		 $.HN.message.alert('药品编码不能为空！', '提示信息', 'error');
            		 return;
            	 } else if (!/^[a-zA-Z0-9_]+$/.test($.trim($("#drugCode").val()))){
            		 $.HN.message.alert('药品编码只能由字线和数字组成！', '提示信息', 'error');
            		 return;
            	 }
            	 if ($.trim($("#drugName").val()).lenght<1){
            		 $.HN.message.alert('通用名不能为空！', '提示信息', 'error');
            		 return;
            	 }
            	 
            	 var drugform2 = $("#drugform2").val();
            	 if (drugform2.length < 1){
            		 drugform2 = $("#drugform1").val(); 
            		 
            	 }
            	 $("#formId").val(drugform2);
            	 if ($.trim($("#formId").val())==""){
            		 $.HN.message.alert('请选择剂型！', '提示信息', 'error');
            		 return;
            	 }
                 var phar = $("#phar3").val();
                 if (phar.length < 1){
                	 phar = $("#phar2").val();
                 }
                 if (phar.length < 1){
                	 phar = $("#phar1").val();
                 }
                 if (phar.length < 1){
                	 phar = $("#pharbig").val();
                 }
            	 $("#pharId").val(phar);
            	 if ($.trim($("#pharId").val())==""){
            		 $.HN.message.alert('请选择药理！', '提示信息', 'error');
            		 return;
            	 }
            	 if ($.trim($("#specId").val())==""){
            		 $.HN.message.alert('请选择规格！', '提示信息', 'error');
            		 return;
            	 }
            	 if ($.trim($("#factor").val())==""){
            		 $.HN.message.alert('转换系数不能为空！', '提示信息', 'error');
            		 return;
            	 } else if (!/^\d+$/.test($.trim($("#factor").val()))){
            		 $.HN.message.alert('转换系数只能是整数！', '提示信息', 'error');
            		 return;
            	 }
            	 if ($.trim($("#materialId").val())==""){
            		 $.HN.message.alert('请选择材质！', '提示信息', 'error');
            		 return;
            	 }
            	 if ($.trim($("#prodPompId").val())==""){
            		 $.HN.message.alert('请选择生产企业！', '提示信息', 'error');
            		 return;
            	 }
            	 if ($.trim($("#drugAttr").val())==""){
            		 $.HN.message.alert('请选择基本药物属性！', '提示信息', 'error');
            		 return;
            	 }
            	 if ($.trim($("#patternType").val())==""){
            		 $.HN.message.alert('请选择专利类型！', '提示信息', 'error');
            		 return;
            	 }
            	 if ($.trim($("#drugSource").val())==""){
            		 $.HN.message.alert('请选择药品来源！', '提示信息', 'error');
            		 return;
            	 }
            	 if ($.trim($("#isLowprice").val())==""){
            		 $.HN.message.alert('请选择是否低价药！', '提示信息', 'error');
            		 return;
            	 }
            	 if ($.trim($("#isAgriculture").val())==""){
            		 $.HN.message.alert('请选择是否农合！', '提示信息', 'error');
            		 return;
            	 }
            	 if ($.trim($("#isHealthcare").val())==""){
            		 $.HN.message.alert('请选择是否医保！', '提示信息', 'error');
            		 return;
            	 }
            	 
            	 $('#form1').submit();
             }
         });
   }
	$('#form1').ajaxForm({ 
	    dataType: 'json', 
	    
    	success: function(returnData) {
    	if(returnData == "success") {
    		$.HN.message.alert('添加成功！', '提示信息', 'success');
    	   window.location.href="${pageContext.request.contextPath }/stdDrug/list.html";
		}else{
			$.HN.message.alert('添加失败，请重新添加！', '提示信息', 'success');
    	}
       } 	
   });
	
   function back(){
   	window.location.href="${pageContext.request.contextPath}/stdDrug/list.html";
   }
   
   $("#gridlist1").jqGrid({
       url: "${pageContext.request.contextPath}/stdCompinfo/stdCompinfoList.html",
       mtype: "POST",
       datatype: "json",
       autowidth: true,
       height: 255,
       shrinkToFit: false,
       colNames: ['id','企业编码','企业名称', '组织机构代码','法人代表'],
       colModel: [
{ name: 'compId',hidden:true,key:true, index: 'sdate', width: 90, align: "center"},
			{ name: 'compCode', index: 'sdate', width: 90, align: "center"},
           { name: 'compName', index: 'sdate', width: 250, align: "left"},
           { name: 'orgCode', index: 'name', width:100, align: "center" },
           { name: 'lrName', index: 'name', width:80, align: "center" }
       ],
       rowNum: 10,
       rowList: [10, 20, 30],
       rownumbers: true,
       pager: "#gridpage1",
       //multiselect: true, 
       viewrecords: true,
       caption: "企业选择", 	
       jsonReader: {
           repeatitems: false,
           id: "ids"
       }
   });
   $("#gridlist1").jqGrid('navGrid', '#gridpage1', { add: false, edit: false, del: false, search: false, refresh: false });
   $(window).trigger("resize");
   
   
   
   $("#gridlist2").jqGrid({
       url: "${pageContext.request.contextPath}/dicDrugspec/dicDrugspecList.html",
       mtype: "POST",
       datatype: "json",
       autowidth: true,
       height: 255,
       //shrinkToFit: false,
       colNames: ['id','规格编码','规格名称'],
       colModel: [
{ name: 'specId',hidden:true,key:true, index: 'sdate', width: 90, align: "center"},
			{ name: 'specCode', index: 'sdate', width: 200, align: "center"},
           { name: 'specName', index: 'sdate', width: 350, align: "left"}
       ],
       rowNum: 10,
       rowList: [10, 20, 30],
       rownumbers: true,
       pager: "#gridpage2",
       //multiselect: true, 
       viewrecords: true,
       caption: "规格选择", 	
       jsonReader: {
           repeatitems: false,
           id: "ids"
       }
   });
   $("#gridlist2").jqGrid('navGrid', '#gridpage2', { add: false, edit: false, del: false, search: false, refresh: false });
   $(window).trigger("resize");
   function editPsComp() {
		$('#editPsComp').modal({
			keyboard : true
		});
	}
   
   function selectComp(){
	   
		$("#compCode").val("");
	    $("#compName").val("");
	    gridSerch();
	   $('#selectComp').modal({
			keyboard : true
		});
	   
	   //window.open("${pageContext.request.contextPath}/stdDrug/toSelectComp.html?value=prodPompId&text=comp","newwin","dialogHeight: 200px; dialogWidth: 150px; dialogTop: 458px; dialogLeft: 166px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;");
   }
   function gridSerch() {
   	var compCode = $("#compCode").val();
   	var compName = $("#compName").val();
		$("#gridlist1").jqGrid('setGridParam',{  
	        datatype:'json',
	        postData:{"compCode":compCode,
	        		"compName":compName}
	    }).trigger("reloadGrid"); //重新载入  
	}
   function gridOk(){
	   var compId = $("#gridlist1").jqGrid('getGridParam', 'selrow');
       if (compId == null) {
    	   $.HN.message.alert('请至少选一行！', '提示信息', 'error');
           return;
       }
       var rowdata = $("#gridlist1").jqGrid('getRowData', compId);
       $("#prodPompId").val(compId);
       $("#comp").val(rowdata.compName);
       $("#selectComp").modal("hide");

   }
   function cleandata(){
	   $("#prodPompId").val("");
       $("#comp").val("");
       $("#selectComp").modal("hide");
   }
   
   
   function selectSpec(){
		$("#specName").val("");
	    gridSpecSerch();
	   $('#selectSpec').modal({
			keyboard : true
		});
	   //window.showModalDialog("${pageContext.request.contextPath}/stdDrug/toSelectComp.html","newwin","dialogHeight: 200px; dialogWidth: 150px; dialogTop: 458px; dialogLeft: 166px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;");
  }
  function gridSpecSerch() {
  	var specName = $("#specName").val();
		$("#gridlist2").jqGrid('setGridParam',{  
	        datatype:'json',
	        postData:{"specName":specName}
	    }).trigger("reloadGrid"); //重新载入  
	}
  function gridSpecOk(){
	   var specid = $("#gridlist2").jqGrid('getGridParam', 'selrow');
      if (specid == null) {
   	   $.HN.message.alert('请至少选一行！', '提示信息', 'error');
          return;
      }
      var rowdata = $("#gridlist2").jqGrid('getRowData', specid);
      $("#specId").val(specid);
      $("#txdrugspec").val(rowdata.specName);
      $("#selectSpec").modal("hide");

  }
  function cleanSpecdata(){
	   $("#specId").val("");
      $("#txdrugspec").val("");
      $("#selectSpec").modal("hide");
  }
	</script>
</body>
</html>